package com.googlecode.yoohoo.xmppcore.stanza;

public class ConnectionTimeoutMonitor {
	private long lastConnectTime;
	private int timeout;
	private boolean closeStream;
	
	public ConnectionTimeoutMonitor(int timeout, boolean closeStream) {
		this.timeout = timeout;
		this.closeStream = closeStream;
		
		lastConnectTime = -1;
	}
	
	public void refreshLastConnectTime() {
		lastConnectTime = System.currentTimeMillis();
	}
	
	public boolean isTimeout() {
		return lastConnectTime != -1 && (System.currentTimeMillis() - lastConnectTime) > (1000 * timeout);
	}
	
	public boolean shouldCloseStream() {
		return closeStream;
	}
}
